﻿using System;
using System.Text;
using System.IO;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using webapp4U;
using webapp4U.BOL;

namespace webapp4U.UI
{
    public partial class Address : BasePage
    {

        string strFilePath;
        string strFilePath_en;
        protected void Page_Load(object sender, EventArgs e)
        {
            lblTitle.Text = "Cập nhật thông tin thanh toán";

            strFilePath = Request.PhysicalApplicationPath + "UserUpload/Thanhtoan.txt";
            strFilePath_en = Request.PhysicalApplicationPath + "UserUpload/Thanhtoan_en.txt";

            if (!Page.IsPostBack)
            {
                txtGioithieu.Text = ReadTextFile(strFilePath);
                txtGioithieu_en.Text = ReadTextFile(strFilePath_en);
            }
        }


        public string ReadTextFile(string filePath)
        {
            if (!System.IO.File.Exists(filePath))
            {
                return "";
            }

            using (StreamReader sr = System.IO.File.OpenText(filePath))
            {
                StringBuilder text = new StringBuilder();
                String input;
                while ((input = sr.ReadLine()) != null)
                {
                    text.AppendLine(input);
                }
                sr.Close();
                return text.ToString();
            }
        }



        public void CreateTextFile(string filePath, string text)
        {
            using (StreamWriter sw = System.IO.File.CreateText(filePath))
            {
                sw.WriteLine(text);
                sw.Close();
            }
        }



        protected void btSave_Click(object sender, EventArgs e)
        {
            CreateTextFile(strFilePath, txtGioithieu.Text);
            CreateTextFile(strFilePath_en, txtGioithieu_en.Text);
        }
       
    }
}